#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging

import tornado.ioloop
import tornado.web

from restrpc import handlers
from restrpc.rpc_client import RPCClient


logger = logging.getLogger(__name__)


def make_app(app_name, amqp_url, **kwargs):

    root = (r"/?", handlers.MainHandler)
    status = (r"/v1/{}/status/?".format(app_name), handlers.StatusHandler)
    tasks = (r"/v1/{}/tasks/?".format(app_name), handlers.TaskHandler)

    web_handlers = [
        root,
        tasks,
        status,
    ]

    rpc_client = RPCClient(app_name, amqp_url)

    rpc_client.init()
    app = tornado.web.Application(web_handlers, rpc_client=rpc_client, **kwargs)

    return app
